package com.study.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RestfullController {


    //原来的请求URL风格：http://localhost:8080/sc/add?a=1&b=2

//    @RequestMapping("/add")
//    public String test(int a, int b, Model model){
//
//        int sum = a + b;
//        model.addAttribute("msg","result:"+sum);
//        return "hello";
//    }

    //RESTful请求风格：http://localhost:8080/sc/add/a/b

    //@RequestMapping("/add/{a}/{b}")
    @GetMapping("/add/{a}/{b}")
    public String test(@PathVariable int a, @PathVariable int b, Model model){

        int sum = a + b;
        model.addAttribute("msg","result:"+sum);
        return "hello";
    }

}
